package com.example.myapplication.view.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import android.os.Bundle;

import com.example.myapplication.R;
import com.example.myapplication.databinding.ActivityMainBinding;
import com.example.myapplication.model.entity.User;

public class MainActivity extends AppCompatActivity {


    private ActivityMainBinding mainBinding = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        User user = new User("ljq", 18, true);
        MutableLiveData<User> udata = new MutableLiveData<>();
        udata.postValue(user);
        mainBinding.setUser(user);
        mainBinding.updateBtn.setOnClickListener(v->{
            user.setName("张三");
            udata.setValue(new User("ly", 20, false));
        });
        udata.observe(this, user1 -> {
            mainBinding.setUser(user1);
        });
    }


}

